package lablayer.model.MathComponents;

import lablayer.model.ComponentFactory;
import lablayer.model.Componentable;
import lablayer.model.LabData;

/**
 * @author Darkness
 */

class VariationCoefficient implements MathComponent {
    private LabData result;

    private LabData data;

    private String componentName = "Коэффициент вариации";

    private String componentId = "4";

    public VariationCoefficient() {
        super();
        this.result = new LabData();
    }
    
    @Override
    public LabData getData() {
        return this.data;
    }

    @Override
    public void calculate() {
        Double value = 0.0;
        Double S = 0.0;
        Double M = 0.0;
       
        Componentable middleValue = ComponentFactory.createComponent(
            MathComponentFactory.createMiddleValue());
        Componentable standartDeviation = ComponentFactory.createComponent(
            MathComponentFactory.createStandardDeviation());
        middleValue.setData(this.data);
        middleValue.calculate();
        standartDeviation.setData(this.data);
        standartDeviation.calculate();
        
        M = ((middleValue.getResult()).getData())[0][0][0];
        S = ((standartDeviation.getResult()).getData())[0][0][0];
        value = (S / M) * 100;
        this.result = new LabData(LabData.parseString(value.toString()));
    }

    @Override
    public void setData(LabData data) {
        if (data != null) {
            this.data = data;
        } else {
            throw new NullPointerException("Null pointer data");
        }
    }

    @Override
    public String getComponentId() {
        return this.componentId;
    }

    @Override
    public String getComponentName() {
        return this.componentName;
    }

    @Override
    public LabData getResult() {
        return this.result;
    }

	@Override
	public void setParameter(String params, String values) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public LabData getInitData() {
		throw new UnsupportedOperationException("Not supported yet.");
	}
}
